# $Id$
# Maintainer: Jan de Groot <jgc@archlinux.org>
# Contributor: Alessio 'mOLOk' Bolognino <themolok@gmail.com>
# Contributor: daniel g. siegel <dgsiegel@gmail.com>

pkgname=libsmbios
pkgver=2.3.3+12+g59d5df9
pkgrel=1
pkgdesc="A library for providing access to as much BIOS information as possible"
arch=('i686' 'x86_64')
url="https://github.com/dell/libsmbios"
license=('GPL' 'custom')
depends=('gcc-libs')
makedepends=('libxml2' 'python2' 'chrpath' 'doxygen' git cppunit)
optdepends=('python2: tools')
_commit=59d5df9ea2deee3b03c02c68a5026733b0f193ba  # master
source=("git+https://github.com/dell/libsmbios.git#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^v//;s/-/+/g'
}

prepare() {
  cd $pkgname
  ./autogen.sh --no-configure
}

build() {
  unset MAKEFLAGS
  cd $pkgname
  mkdir build
  cd build
  PYTHON=python2 ../configure --prefix=/usr --sbindir=/usr/bin --sysconfdir=/etc --disable-static --enable-libsmbios_cxx
  make
}

package() {
  cd $pkgname/build
  make DESTDIR="${pkgdir}" install

  chrpath -d "${pkgdir}/usr/bin/smbios-sys-info-lite"
  install -m755 -d "${pkgdir}/usr/include"
  cp -a ../src/include/* "${pkgdir}/usr/include/"
  cp -a out/public-include/* "${pkgdir}/usr/include/"

  rm -rf "${pkgdir}/etc/yum"
  rm -rf "${pkgdir}/usr/lib/yum-plugins"

  sed -e 's|#!/usr/bin/python|#!/usr/bin/python2|g' \
      -i "${pkgdir}"/usr/bin/smbios-{{wakeup,token,wireless,keyboard,thermal}-ctl,lcd-brightness,passwd,sys-info,battery-ctl}

  install -m755 -d "${pkgdir}/usr/share/licenses/${pkgname}"
  install -m644 ../COPYING-OSL "${pkgdir}/usr/share/licenses/${pkgname}/"

  python2 -m compileall "${pkgdir}/usr/lib/python2.7/site-packages/libsmbios_c/"
}
